package com.zjun.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.LocalDate;

public class FormatterUtils {


    //保存为两位小数
    public static String NumFormat(double number) {
        return String.format("%.2f", number).toString();
    }

    //日期格式化
    public static LocalDateTime DateFormat(String dateString) {


        // 定义日期格式
        DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm");
        DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        // 将字符串解析为LocalDateTime对象
        LocalDateTime dateTime = LocalDateTime.parse(dateString, inputFormatter);

        // 格式化为"年-月-日"字符串
        String formattedDateString = dateTime.format(outputFormatter);

        return dateTime;
    }

}




